package com.lankystar.logistucs.spring.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.logistucs.spring.dao.ITwoOrderDao;
import com.lankystar.logistucs.spring.entity.TwoOrder;
import com.lankystar.logistucs.spring.entity.TwoStatus;

@Repository
public class TwoOrderDaoImpl extends BaseDaoImpl implements ITwoOrderDao {

	@Autowired
	private SessionFactory sf;
	
	public Session getSession(){
		System.out.println("session  TwoOrderDaoImpl!!");
		return sf.getCurrentSession();
	}

	@Override
	public TwoOrder selectTwoOrderById(int twoOrderId) {
		TwoOrder twoOrder = (TwoOrder) getSession().get(TwoOrder.class, twoOrderId);
		return twoOrder;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TwoStatus> selectTwoStatusKeyById(int twoOrderId) {
		String sql = "select ts from TwoOrderAndTwoStatus tat join tat.twoOrder to join tat.twoStatus ts where to.twoOrderId = "+twoOrderId+"";
		List<TwoStatus> ints = getSession().createQuery(sql).list();
		return ints;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TwoStatus> selectTwoStatus(int oneOrderId) {
		String hql = "select ts from TwoOrder two join two.tats tat join tat.twoStatus ts join two.oneOrder one where one.oneOrderId = "+oneOrderId+"";
		List<TwoStatus> twoStatuslist = getSession().createQuery(hql).list();
		return twoStatuslist;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TwoOrder> selectTwoOrderByOneOrderId(int oneOrderId) {
		String hql = "select two from TwoOrder two join two.oneOrder one where one.oneOrderId = ?";
		List<TwoOrder> twoOrderlist = getSession().createQuery(hql).setInteger(0, oneOrderId).list();
		return twoOrderlist;
	}
}
